package org.example.hadoop3;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Mapper Reduce Driver
 * 1.继承类或实现接口
 * 2.实现或重写方法
 * 3.提交执行
 * Driver将写好的mr封装成Job对象，然后提交执行。
 */
public class MapReduce01 {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // 创建配置对象
        Configuration conf = new Configuration();
//        conf.set("fs.defaultFS", "hdfs://hadoop1:8020");
//        conf.set("mapreduce.framework.name", "yarn");
//        conf.set("mapreduce.app-submission.cross-platform", "true");
//        conf.set("yarn.resourcemanager.hostname", "hadoop3");
        // 创建Job对象
        Job job = Job.getInstance(conf);
        // 关联驱动
        job.setJarByClass(MapReduce01.class);
        //job.setJar("");
        // 关联mapper和reducer
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReduce.class);
        // 设置mapper的输出key和value类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        // 设置最终输出的key value
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        // 设置输入输出路径
//        FileInputFormat.setInputPaths(job, new Path("/Users/gaoqiang/dev/aa.txt"));
//        FileOutputFormat.setOutputPath(job, new Path("/Users/gaoqiang/dev/output"));
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        // 提交Job
        job.waitForCompletion(true);
    }
}
